package com.kgc.scd.controller;

import com.kgc.scd.service.SendMessageService;
import com.kgc.scd.util.RedisUtils;
import com.kgc.scd.util.Sample;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created On : 2022/11/17 0017.
 * <p>
 * Author : shiguangchuan
 * <p>
 * Description: 设置到货提醒的相关操作入口
 */
@Slf4j
@RestController
@RequestMapping("/sgcServer")
public class SendMessageGoods {

    //@Autowired
    //private Sample sample;

    @Autowired
    private SendMessageService sendMessageService;

    /**
     * @author : shiguangchuan
     * @date   : 2022/11/17 0017
     * @param  : [userId, phoneNum]
     * @return : boolean
     * @description : 登记商品补仓提醒
     */
    @GetMapping("/needSendMessage")
    public boolean needSendMessageGoods(@RequestParam String phoneNum,@RequestParam String goodsId){

        // 调用业务实现到货提醒登记
        return sendMessageService.needSendMessageGoods(phoneNum,goodsId);

    }


    /**
     * @author : shiguangchuan
     * @date   : 2022/11/17 0017
     * @param  : [goodsId, goodsNumber]
     * @return : void
     * @description : 模拟加仓后对有登记提醒的用户发送短信通知
     */
    @PostMapping("/addGoodsStock")
    public void addGoodsStockToSendMessage(@RequestParam String goodsId,@RequestParam Integer goodsNumber){

        // 调用业务接口执行加仓并发送消息队列
        sendMessageService.addGoodsStockToSendMessage(goodsId,goodsNumber);

    }

    public static void main(String[] args) throws Exception {

        Sample sample1 = new Sample();
        if (sample1.sendSms("173476737")){

            log.info("---- 发送短信成功 ----");
            return;

        }

        log.info("---- 发送短信失败 ----");
    }

}
